﻿@{
    Layout = "~/Areas/Mall/Views/Shared/_HomeLayout.cshtml";
    var memberLogin = ViewData["WebHeadMember"] as MemberLogin;
}

<link rel="stylesheet" href="~/Areas/Mall/css/head.css">
<link rel="stylesheet" href="~/Areas/Mall/css/login.css">
<div class="reinstall">
    <div class="top">
        <span>修改密码</span>
    </div>
    <div class="content">
        <input id="txtId" type="hidden" value="@memberLogin.Id" />
        <div class="item">
            <span>账户/手机</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.UserName"></p>
        </div>
        <div class="item">
            <span>旧登录密码</span>
            <p><input id="txtOldPassWord" type="password" class="input normal important"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请输入旧密码</span></p>
        </div>
        <div class="item">
            <span>新登录密码</span>
            <p><input id="txtFirstPassWord" type="password" class="input normal important"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请输入新密码</span></p>
        </div>
        <div class="item">
            <span>新确认密码</span>
            <p><input id="txtSecondPassWord" type="password" class="input normal important"><span class="wrong"><img src="~/Areas/Mall/image/error.png" />请再输入一次新密码</span></p>
        </div>
        <div class="item">
            <span>省市区</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.Place"></p>
        </div>
        <div class="item">
            <span>学校名称</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.SchoolName"></p>
        </div>
        <div class="item">
            <span>校长名称</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.RealName"></p>
        </div>
        <div class="item">
            <span>校长电话</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.Phone"></p>
        </div>
        @*<div class="item">
            <span>邮箱</span>
            <p><input type="text" readonly="readonly" class="input normal" value="@memberLogin.Email"></p>
        </div>*@
    </div>
    <div class="btn-wrap" style="position: static;">
        <input type="submit" value="提交保存" class="btn" onclick="resetPW()">
        <input type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);">
    </div>
</div>

<script type="text/javascript">
    $(".item .important").blur(function () {
        if ($(this).val()) {
            $(this).parent().find('.wrong').hide();
            $(this).removeClass('error')
        } else {
            $(this).parent().find('.wrong').show();
            $(this).addClass('error')
        }
    });

    //检测
    function check() {
        var retBool = true;

        //旧登录密码
        var oldPassWord = $("#txtOldPassWord").val();
        if (oldPassWord == undefined || oldPassWord == null || oldPassWord == "") {
            $("#txtOldPassWord").parent().find('.wrong').show();
            $("#txtOldPassWord").addClass('error');
            retBool = false;
        } else {
            $("#txtOldPassWord").parent().find('.wrong').hide();
            $("#txtOldPassWord").removeClass('error');
        }

        //新登录密码
        var firstPassWord = $("#txtFirstPassWord").val();
        if (firstPassWord == undefined || firstPassWord == null || firstPassWord == "") {
            $("#txtFirstPassWord").parent().find('.wrong').show();
            $("#txtFirstPassWord").addClass('error');
            retBool = false;
        } else {
            $("#txtFirstPassWord").parent().find('.wrong').hide();
            $("#txtFirstPassWord").removeClass('error');
        }

        //新确认密码
        var secondPassWord = $("#txtSecondPassWord").val();
        if (secondPassWord == undefined || secondPassWord == null || secondPassWord == "") {
            $("#txtSecondPassWord").parent().find('.wrong').show();
            $("#txtSecondPassWord").addClass('error');
            retBool = false;
        } else {
            $("#txtSecondPassWord").parent().find('.wrong').hide();
            $("#txtSecondPassWord").removeClass('error');
        }

        return retBool;
    };

    //重置密码
    function resetPW() {
        if (check()) {
            var id = $("#txtId").val();
            var oldPassWord = $("#txtOldPassWord").val();
            var firstPassWord = $("#txtFirstPassWord").val();
            var secondPassWord = $("#txtSecondPassWord").val();

            $.ajax({
                type: "POST",
                url: '@Url.Action("RestPassWord", "Home")',
                data: {
                    "id": id,
                    "oldPassWord": oldPassWord,
                    "firstPassWord": firstPassWord,
                    "secondPassWord": secondPassWord
                },
                success: function (res) {
                    if (res.Success) {
                        alert(res.Message);
                        window.location.href = res.Data + '?r=' + (new Date()).valueOf();//直接跳转
                    } else {
                        alert(res.Message);
                    }
                }
            });
        }
    }
</script>